package design_pattern

import "fmt"

type Handler interface {
	Handle(score int)
}

type ConcreteHandlerOne struct {
	Handler
}

func (r *ConcreteHandlerOne) Handle(score int) {
	if score < 0 {
		fmt.Println("ConcreteHandler1 处理")
		return
	}
}

type ConcreteHandlerTwo struct {
	Handler
}

func (r *ConcreteHandlerTwo) Handle(score int) {
	if score > 0 {
		fmt.Println("ConcreteHandler2 处理")
		return
	}
}

type ConcreteHandlerThree struct {
	Handler
}

func (r *ConcreteHandlerThree) Handle(score int) {
	if score == 0 {
		fmt.Println("ConcreteHandler3 处理")
		return
	}
}

type ChainHandler struct {
	handlers []Handler
}

func (r *ChainHandler) AddHandler(handler Handler) {
	r.handlers = append(r.handlers, handler)
}
func (r *ChainHandler) Handle(score int) {
	for _, handler := range r.handlers {
		handler.Handle(score)
	}
}

func main2() {
	chain := &ChainHandler{}
	chain.AddHandler(&ConcreteHandlerOne{})
	chain.AddHandler(&ConcreteHandlerTwo{})
	chain.AddHandler(&ConcreteHandlerThree{})
	chain.Handle(10)
}
